<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间问候</title>
</head>
<body>
    <div id="greetingDiv"></div>

    <script>
        function updateGreeting() {
            var now = new Date();
            var hour = now.getHours();
            var greeting;

            if (hour >= 22 || hour < 6) {
                greeting = "夜里好";
            } else if (hour >= 6 && hour < 9) {
                greeting = "早上好";
            } else if (hour >= 9 && hour < 12) {
                greeting = "上午好";
            } else if (hour >= 12 && hour < 14) {
                greeting = "中午好";
            } else if (hour >= 14 && hour < 17) {
                greeting = "下午好";
            } else if (hour >= 17 && hour < 19) {
                greeting = "傍晚好";
            } else if (hour >= 19 && hour < 22) {
                greeting = "晚上好";
            }

            document.getElementById("greetingDiv").textContent = greeting;
        }

        // 当文档加载完成时，调用updateGreeting函数
        document.addEventListener("DOMContentLoaded", updateGreeting);
    </script>
</body>
</html>